package NC85_拼接所有的字符串产生字典序最小的字符串;

import java.util.Comparator;
import java.util.PriorityQueue;

public class Solution {
    /**
     *
     * @param strs string字符串一维数组 the strings
     * @return string字符串
     */
    public String minString (String[] strs) {
        // write code here
        if (strs == null || strs.length < 1){
            return null;
        }
        PriorityQueue<String> heap = new PriorityQueue<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o1 + o2).compareTo(o2 + o1);
            }
        });
        for (String s: strs){
            heap.offer(s);
        }
        StringBuilder sb = new StringBuilder();
        while (!heap.isEmpty()){
            sb.append(heap.poll());
        }
        return sb.toString();
    }
}